package com.offer;


import com.utils.DataUtils;

public class Test57_1 {

    public int[] twoSum(int[] nums, int target) {

        int left = 0, right = nums.length - 1;

        while (left < right) {
            int sum = nums[left] + nums[right];

            if (sum > target) {
                right--;
            } else if (sum < target) {
                left++;
            } else {
                return new int[]{nums[left], nums[right]};
            }
        }

        return new int[2];
    }

    public static void main(String[] args) {
        Test57_1 test = new Test57_1();
//        DataUtils.printArray(test.twoSum(new int[]{10, 26, 30, 31, 47, 60}, 40));
//        DataUtils.printArray(test.twoSum(new int[]{14, 15, 16, 22, 53, 60}, 76));
        DataUtils.printArray(test.twoSum(new int[]{21, 44, 45, 54, 62, 73, 74, 74, 74, 81}, 128));
    }

}
